package com.business.form.service;

import java.util.List;
import java.util.Arrays;

import com.business.system.common.base.BaseService;
import com.business.system.common.support.Convert;
import com.business.system.model.custom.Tablepar;
import com.business.system.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.business.form.mapper.auto.FormInfoMapper;
import com.business.form.model.auto.FormInfo;
import com.business.form.model.auto.FormInfoExample;

/**
 * 表单详情 FormInfoService
 * @Title: FormInfoService.java 
 * @Package com.business.form.service 
 * @author lujingyuan_自动生成
 * @email 
 * @date 2020-06-18 10:28:34  
 **/
@Service
public class FormInfoService implements BaseService<FormInfo, FormInfoExample> {
	@Autowired
	private FormInfoMapper formInfoMapper;
	
      	   	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<FormInfo> list(Tablepar tablepar, String name){
	        FormInfoExample testExample=new FormInfoExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andNameLike("%"+name+"%");
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<FormInfo> list= formInfoMapper.selectByExample(testExample);
	        PageInfo<FormInfo> pageInfo = new PageInfo<FormInfo>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista= Convert.toListStrArray(ids);
			FormInfoExample example=new FormInfoExample();
			example.createCriteria().andIdIn(lista);
			return formInfoMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public FormInfo selectByPrimaryKey(String id) {
				
			return formInfoMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(FormInfo record) {
		return formInfoMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(FormInfo record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());

		return formInfoMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(FormInfo record, FormInfoExample example) {
		
		return formInfoMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(FormInfo record, FormInfoExample example) {
		
		return formInfoMapper.updateByExample(record, example);
	}

	@Override
	public List<FormInfo> selectByExample(FormInfoExample example) {
		
		return formInfoMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(FormInfoExample example) {
		
		return formInfoMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(FormInfoExample example) {
		
		return formInfoMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param formInfo
	 * @return
	 */
	public int checkNameUnique(FormInfo formInfo){
		FormInfoExample example=new FormInfoExample();
		example.createCriteria().andNameEqualTo(formInfo.getName());
		List<FormInfo> list=formInfoMapper.selectByExample(example);
		return list.size();
	}


}
